package com.yygo.webapp.controller;

import com.yygo.model.LoanRequest;
import com.yygo.service.LoanRequestManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ExtendedModelMap;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * Created by tiansha on 2015/7/20.
 */
@Controller
@RequestMapping("/globalSearch*")
public class GlobalSearchController {

    @Autowired
    private LoanRequestManager loanRequestManager;

    @RequestMapping(method = RequestMethod.GET)
    public ModelAndView globalSearch(String q) {
        Model model = new ExtendedModelMap();
        List<LoanRequest> loanRequests = loanRequestManager.search(q, LoanRequest.class);
        model.addAttribute(loanRequests);

        return new ModelAndView("myloanrequests", model.asMap());
    }
}
